package boni.si;



import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;

import boni.JSON.InfoImporter;
import boni.JSON.URLgetter;


import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;






public class oddaj_komentar extends Dialog implements OnClickListener {
	Button Button01;
	EditText vsebina;
	EditText komentator;
	String param1;
	String param2;
	String param3;
	LinearLayout LinearLayout03;
	LokalPodrobnosti referenca;
	
	public oddaj_komentar(Context context, String param1, String param2, String param3, LokalPodrobnosti referenca) {
		super(context);
		
		/** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		/** Design the dialog in main.xml file */
		setContentView(R.layout.komentar_oddaja); //napolnimo ekran
		

		Button01 = (Button) findViewById(R.id.gumbKomentarOddan);//najdemo gumb
		Button01.setOnClickListener(this);//nastavimo poslušalca
		
		vsebina = (EditText) findViewById(R.id.etKomentar);//najdemo gumb
		
		komentator = (EditText) findViewById(R.id.etKomentator);//najdemo gumb
		
		LinearLayout03 = (LinearLayout) findViewById(R.id.LinearLayout03);//najdemo gumb
		
		this.param1 = param1;
		this.param2 =param2;
		this.param3 = param3;
		
		this.referenca = referenca;
	}



	@Override
	public void onClick(View arg0) {
		if(arg0==Button01){
			
			//enkodiram string
			String kodiranParam1 = URLEncoder.encode(vsebina.getText().toString());
			String kodiranParam2 = URLEncoder.encode(komentator.getText().toString());

			//enkodiram string
			String kodiranParam3 = URLEncoder.encode(param1);
			String kodiranParam4 = URLEncoder.encode(param2);
			String kodiranParam5 = URLEncoder.encode(param3);
			
	    	String parametri = "?izjava=" + kodiranParam1 + "&komentator=" + kodiranParam2
	    	+ "&nazivLokala=" + kodiranParam3 + "&naslovLokala=" + kodiranParam4 +"&mestoLokala=" +kodiranParam5;
	    	
			//zapis komentarja
	    	URLgetter urlNaslov = new URLgetter();
			String naslov = urlNaslov.getURL() + "komentiraj.ashx" + parametri;
			try {
				InfoImporter idiNaURL = new InfoImporter();
				idiNaURL.getStringFromURL(naslov);
			} catch (Exception e) {
				Log.d("subvencionirana.obvestilo", e.toString());
			}
			Log.d("subvencionirana.obvestilo", "ulala");
			referenca.posodobiFormo();
			this.cancel();
			
		}
		
	}
	
  
}
